package com.area.cth.controller;

import com.area.cth.pojo.CommentGoods;
import com.area.cth.pojo.CommentPost;
import com.area.cth.common.PageBean;
import com.area.cth.common.Result;
import com.area.cth.service.CommentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "评论相关接口")
@RestController
@RequestMapping("/comment")
@CrossOrigin
public class CommentController {
    @Autowired
    private CommentService cs;

    @Operation(summary = "新增帖子评论")
    @PostMapping("/addToPost")
    public Result addCommentToPost(@RequestBody CommentPost c) {
        cs.addCommentToPost(c);
        return new Result(0,"评论成功",null);
    }

    @Operation(summary = "新增商品留言")
    @PostMapping("/addToGoods")
    public Result addCommentToGoods(@RequestBody CommentGoods c) {
        cs.addCommentToGoods(c);
        return new Result(0,"留言成功",null);
    }

    @Operation(summary = "根据帖子id查询评论")
    @GetMapping("/getForPost")
    public Result<List<CommentPost>> commentPostList(Integer pId) {
        List<CommentPost> commentPostList = cs.getCommentPostList(pId);
        return Result.success(commentPostList);
    }

    @Operation(summary = "根据商品id查询留言")
    @GetMapping("/getForGoods")
    public Result<List<CommentGoods>> commentGoodsList(Integer gId) {
        List<CommentGoods> commentGoodsList = cs.getCommentGoodsList(gId);
        return Result.success(commentGoodsList);
    }

    @Operation(summary = "根据帖子id查询评论数量")
    @GetMapping("/postCommentCount")
    public Result<Integer> postCommentCount(Integer pId) {
        Integer count = cs.postCommentCount(pId);
        return Result.success(count);
    }

    @Operation(summary = "查询个人社区评论")
    @GetMapping("/getForMyPost")
    public Result<List<CommentPost>> commentPostListForMine() {
        List<CommentPost> myCommentPosts = cs.commentPostListForMine();
        return Result.success(myCommentPosts);
    }

    @Operation(summary = "分页查询社区评论")
    @GetMapping("/getForPostList")
    public Result<PageBean<CommentPost>> commentPostList(Integer pageNo, Integer pageSize) {
        PageBean<CommentPost> commentPosts = cs.commentPostList(pageNo, pageSize);
        return Result.success(commentPosts);
    }

//    @Operation(summary = "获取留言列表分页")
//    @GetMapping("/getForGoodsList")
//    public Result<IPage<CommentGoods>> commentGoodsList(Integer pageNo, Integer pageSize) {
//        IPage<CommentGoods> commentGoods = cs.commentGoodsList(pageNo, pageSize);
//        return Result.success(commentGoods);
//    }

    @Operation(summary = "查询个人商品留言")
    @GetMapping("/getForMyGoods")
    public Result<List<CommentGoods>> commentGoodsListForMine() {
        List<CommentGoods> myCommentGoods = cs.commentGoodsListForMine();
        return Result.success(myCommentGoods);
    }

    @Operation(summary = "删除帖子评论")
    @DeleteMapping("/delPost")
    public Result deletePost(Integer id) {
        cs.deletePost(id);
        return new Result(0,"删除成功",null);
    }

    @Operation(summary = "删除商品留言")
    @DeleteMapping("/delGoods")
    public Result deleteGoods(Integer id) {
        cs.deleteGoods(id);
        return new Result(0,"删除成功",null);
    }
}
